package com.example.rocketmqdemo.controller;


import com.alibaba.fastjson.JSON;
import com.example.rocketmqdemo.content.UserContent;
import com.example.rocketmqdemo.producer.UserProducer;
import com.example.rocketmqdemo.service.ProduderService;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.common.RemotingHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class TestController {


    @Autowired
    private ProduderService produderService;

    @RequestMapping("/")
    public Object i(HttpServletRequest request) {
        Map<String, Object> res = new HashMap<String, Object>();
        res.put("ip:", request.getScheme() + "://" + request.getServerName()
                + ":" + request.getServerPort() + request.getRequestURI());
        return res;

    }

    @RequestMapping("/produder")
    public int produder(HttpServletRequest request) {
        List<UserContent> userContentList = new ArrayList<>();
        for (int i = 0; i < 100; i++) {
            UserContent userContent = new UserContent(String.valueOf(i), "abc" + i);
            userContentList.add(userContent);
        }
        produderService.produder_to(userContentList);
        return 1;

    }






}
